layui.define(['laytpl', 'jm'], function (exports) {
    var $ = layui.$,
        setter = layui.setter,
        $body = $('body'),
        layer = layui.layer,
        jm = layui.jm,
        admin = layui.admin,
        platform = {
            init: function () {
                var loading = layer.load(0, { shade: false, time: 2 * 1000 });
                admin.req({
                    url: 'sysUser/getPlatformItem',
                    type: 'get',
                    done: function (res) {
                        if (res.successful) {
                            var platFormLeft = res.data

                            var tmphtml = ``;
                            var btnArr = ['facebook', 'twitter', 'google', 'instagram', 'pinterest'];
                            var tmpstr = ``;
                            platFormLeft.forEach(function (item, index) {
                                if (index == platFormLeft.length - 1) {
                                    tmphtml = tmphtml + tmpstr;
                                }
                                tmphtml += `<div class='sysBox'>`
                                tmphtml += `<a class="btn ${btnArr[index % 4]} litolink"url="${item.url}" id="${item.id}" title="${item.name}" dir="${item.show}" href="#">
                                    <span class="iconfont fa">${item.img}</span>
                                </a>`

                                tmphtml += `<p>${item.name}</p></div>`

                            })
                            $('.selectpageright').append(tmphtml)
                        }
                    }
                });
                layer.close(loading);
            },
            selectSys: function (id, name, url) {
                if (id) {
                    layui.sessionData(layui.setter.tableName + 'dpzs', {
                        key: 'dpzs',
                        remove: true
                    });

                    layui.sessionData(setter.tableName + 'platform', {
                        key: 'platform',
                        value: JSON.stringify({
                            name: name,
                            key: id,
                            url: url
                        })
                    });
                    location.href = "/index.html";

                } else {
                    layer.msg('你没有权限！');
                }
            },
            tohome: function () {
                layui.sessionData(layui.setter.tableName + 'platform', {
                    key: 'platform',
                    remove: true
                });
                layui.sessionData(layui.setter.tableName + 'dpzs', {
                    key: 'dpzs',
                    remove: true
                });
                location.href = 'index.html';
            }
        };

    /* 添加/修改弹出层 */
    $body.on("click", ".litolink", function () {
        var title = $(this).attr("title"); // 系统名称
        var id = $(this).attr("id"); // 系统标识  
        var dir = $(this).attr("dir");
        var url = $(this).attr("url");
        var title = $(this).attr('title');
        if (dir == 'true') {
            //大屏跳转
            if (url.indexOf("dataview/") > -1) {
                window.open("/src/views/dataview/index.html", "_blank");
                // var container = layui.view(setter.container);
                // location.href = "/src/views/sjdp/sjdp_rcjg.html";
                // container.render('src/views/sjdp/sjdp_rcjg').done(function () {
                //     layui.sessionData(setter.tableName + 'sjdp', {
                //         key: 'sjdp',
                //         value: JSON.stringify({
                //             name: title,
                //             key: id,
                //             url: url
                //         })
                //     });
                // });
                // return;
            } 
            else {
                layui.sessionData(setter.tableName + 'platform', {
                    key: 'platform',
                    value: JSON.stringify({
                        name: title,
                        key: id,
                        url: url
                    })
                });
                location.href = "/index.html";
            }


        } else {
            layer.msg('你没有权限访问！');
        }
    });
    $body.on("click", "#downfile", function () {
        layer.open({
            type: 2,
            title: '文件下载',
            shadeClose: true,
            shade: .8,
            area: ['90%', '90%'],
            maxmin: false, //开启最大化最小化按钮
            content: '/html/system/fujians/xtwjxzList.html'
        });
    })

    //对外暴露的接口
    exports('platform', platform);
});